More Loops
Continued from "ALL-ROUND LOOP TEMPLETS" on [My old Homepage]
[Deliver each filename to a function(s)]
[Create a text file]
[Drag & drop a text file to split]
[Work, Construct]
* Deliver.bat
@Echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 1. Drag & drop a file from a directory. ::
:: 2. Get all filenames in that directory. ::
:: 3. Deliver each filename 2 function(s). ::
:: ::
:: Used OS. Win98. ::
:: Functions: Strings.com, (Sed.exe and Pfe32.exe) ::
:: Variables: drive, dir, x, p, count, total ::
:: Filenames: %temp%\: ##1.tmp, ##2.tmp ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
For %%v in ( DRIVE DIR) do Strings %%v=FILE%%v %1
For %%c in (%DRIVE% "Set DRIVE=" Cd%DIR% "Set DIR=") do %%c
Dir .HTM/o/a-d/b >%temp%\##1.tmp %[if all files then remove HTM]%
:: Dir ./o/a-d/b >%temp%\##1.tmp %[if all files]%
:: STATUS %[2. Got all filenames in the directory of your file.]%
::
:: The above program has nothing 2do with the rest - except, that
:: the %temp%\##1.tmp file must contain lines (some kind of data)
::
Echo. >%temp%\##2.tmp %[a log file]%
Set count=0
Strings total=LINESIZE %temp%\##1.tmp
Strings total=ADD %total%, 1
Set p=1
:Loooop -------------------------------- ------------------------
Strings count=ADD %count%, 1
Strings x=READ %temp%\##1.tmp, %count% %[read a line from file]%
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Your/my program goes here. (5 lines:)
Sed 7,9!d %x%|Find "center" >nul %[substitute to what you want.]%
If errorlevel 1 Echo %count%/%total% %x%. No item>>%temp%\##2.tmp
If errorlevel 1 Pfe32 %x%
If %count%==%p% For %%c in (Pfe32 Pause Cls) do %%c
If %count%==%p% Strings p=ADD %count%,9 %[a pause for each 9th.]%
::
If not "%count%"=="%total%" Goto :Loooop ------------------------
For %%f in (1 2) do If exist %temp%\##%%f* Del/p %temp%\##%%f.tmp
For %%v in (x p count total) do Set %%v=
For %%c in (Echo. Pause Cls Exit) do %%c
PS. My program:
If the item (center) was not found between and inclusive line
7 to 9. Then I wanted to edit these files in my Pfe32 editor.
But only 9 files at a time. My editor collected 9 files and I
placed the missing item. It could be done using SED, (without
the editor), but I wanted some more control. Now my DOS Guide
is final and therefore the name of the URL is supposed not to
be changed -- http://2dos.homepage.dk/free/free.html -- Maybe
some small ZIP files to update the big ZIP file, can possible
be uploaded. The location and name of the ZIP file is not 2be
changed but please don't link directly 2it. Links to this HP:
"http://users.cybercity.dk/~bse26236/", it's appreciated. :-)
DKZ.BAT
Created..: June 20, 2000
Last edit: June 20, 2000
@Echo off
For %%f in (trings.com ed.exe) do If not exist %windir%\command\S%%f Goto Q
::
:: Create a text file on the basis of all "file_id.dkz" file(s)
:: found on drive D:
::
For %%v in ( "Set DRIVE=D:" "Set DIR=\") do %%v
For %%c in ("%DRIVE%" "Set DRIVE=" "Cd%DIR%" "Set DIR=") do %%c
Dir file_id.dkz/a-d/b/s > %temp%\##1.tmp
Set count=0
Strings/p+ total=LINESIZE %temp%\##1.tmp
Strings/p+ total=ADD %total% + 1
Rem > %temp%\##2.tmp
:Loooop -------------------------------- ----------------------
Strings/p+ count=ADD %count% + 1
Strings/p+ x=READ %temp%\##1.tmp+%count%
Echo %count%/%total%
:: Program goes here ===================
::
Echo %x%|sed "s/.://;s/.\{12\}$//">>%temp%\##2.tmp
:: Echo.>>%temp%\##2.tmp
Type %x%|sed "s/^[ \t]*//;s/[ \t]*$//;/^$/d">>%temp%\##2.tmp
Echo _______________________________________>>%temp%\##2.tmp
::
:: =====================================
If not (%count%)==(%total%) Goto :Loooop ----------------------
Sed "s/\. /&\n/g" %temp%\##2.tmp >%temp%\##1.tmp
Notepad %temp%\##1.tmp %[REM Pfe32.exe]%
Erase %temp%\##2.tmp
Erase %temp%\##1.tmp/p
For %%v in ( x count total ) do Set %%v=
For %%c in (Cls Exit) do %%c
:Q Missing files
Type %0|Find "\S%%%%f Goto Q"|Find/v "!"
For %%p in (. . .:Q . ."What about these files: " .) do Echo%%p
For %%f in (Strings.com Sed.exe) do Echo --%windir%\Command\%%f
For %%c in (Echo Echo Pause Cls) do %%c.
@Echo off
:: Drag an drop a text file to split
If (%1)==() Exit
:: Used.....: Strings.com, SED.exe (and Pfe32.exe)
:: Author...: B.Pedersen
:: Test.....: Win98
:: Created..: June 08, 2000
:: Last edit: June 11, 2000
Strings L=linesize %1
Strings L=add %L%, 1
Strings X=div %L%, 2
Strings A=div %L%, 5
Strings B=div %L%, 9
Echo Linesize = %L%
Echo.
Echo Split file in 2 (about %X% line(s) in each file).
Echo Split file in 5 (about %A% line(s) in each file).
Echo Split file in 9 (about %B% line(s) in each file).
Echo.
Choice /c259 ÿPress [ESC] to quit or:ÿ
Echo.
If errorlevel 4 Goto End
If errorlevel 1 Set S=2
If errorlevel 2 Set S=5
If errorlevel 3 Set S=9
Strings X=div %L%,%S%
If %X%==0 For %%c in ("Echo File to small" Echo. Pause Cls "%0 %1") do %%c
For %%v in (L A) do Set %%v=1
:Loop
Strings B=mul %L%,%X%
Strings D=length %A%%B%
Strings D=sub 16,%D%
Strings D=REPEAT %D%, ÿ
Echo %L% %D%%A%-%B% %temp%\p0%L%_0%S%.tmp (%X% Lines) > CON
Sed "%A%,%B%!d" %1 >%temp%\p0%L%_0%S%.tmp
For %%v in ("L=add %L%" "A=add %B%") do Strings %%v,1
If not (%L%)==(%S%) Goto Loop
Strings D=linesize %1
Strings D=add %D%,1
Strings X=sub %D%,%B%
Strings B=length %A%%D%
Strings B=sub 16,%B%
Strings B=REPEAT %B%, ÿ
Echo %L% %B%%A%-%D% %temp%\p0%L%_0%S%.tmp (%X% Lines).> CON
Sed "%A%,$!d;" %1 > %temp%\p0%L%_0%S%.tmp
For %%c in (Echo. Pause) do %%c
If exist %windir%\command\Pfe32.exe Pfe32 %temp%\p*0%S%.tmp
Rem|Choice/Cÿ/N/Tÿ,02<NUL
Del/p %temp%\p0*_0%S%.tmp
:End
For %%v in (S D X L A B) do Set %%v=
For %%c in (Cls Exit) do %%c
Rem L34. For %%v in (L B) do Set %%v=0
Rem L43. move L43 from bottom to top of loop (L37)
Rem L45. add Strings A=add %B%,1
Rem L52. Echo %B%%A%-%D% %temp%\p0%L%_0%S%.tmp (+ %X% Lines).
Rem L53. >>
* Work, Construct
When I construct a batch file, then this loop-template is useful.
Created..: Jan 31, 2001.
Note: Strings.com and pfe32.exe are used.
To see why it's useful, just run as it's:
@echo off
if %ask0%'==' set ask0=0
if %ask1%'==' set ask1=25
strings c0= ask Start [%ask0%]:
if %c0%'==' set c0=%ask0%
strings c1= ask & End [%ask1%]:
if %c1%'==' set c1=%ask1%
:loop
echo. [%c0% / %c1%]:
:: if %c0%==12 for %%v in (echo pause echo) do %%v.
if %c0%==%c1% goto end_loop
strings/p+ c0 = add %c0% +1
goto loop
:end_loop
for %%v in ( c0 c1 ) do set %%v=
for %%v in (echo. pause cls) do %%v
pfe32 /g11 %0%
goto eof
:eof
|